﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FourSquareSharp.MVC.Code.FourSquare
{
    public static class FourSquareApi
    {
        public static string UsersSelf(string token)
        {
            var client = new Hammock.RestClient()
            {
                Authority = "https://api.foursquare.com/v2/"
            };
            var request = new Hammock.RestRequest()
            {
                Path = "users/self"
            };
            request.AddParameter("oauth_token", token);
            var response = client.Request(request);
            return response.Content;
        }

        public static string UsersTips(string token)
        {
            var client = new Hammock.RestClient()
            {
                Authority = "https://api.foursquare.com/v2/"
            };
            var request = new Hammock.RestRequest()
            {
                Path = "users/self/tips"
            };
            request.AddParameter("oauth_token", token);
            var response = client.Request(request);
            return response.Content;
        }

        public static string UsersTodos(string token)
        {
            var client = new Hammock.RestClient()
            {
                Authority = "https://api.foursquare.com/v2/"
            };
            var request = new Hammock.RestRequest()
            {
                Path = "users/self/todos"
            };
            request.AddParameter("oauth_token", token);
            request.AddParameter("sort","recent");
            var response = client.Request(request);
            return response.Content;
        }

        public static string UsersCheckins(string token)
        {
            var client = new Hammock.RestClient()
            {
                Authority = "https://api.foursquare.com/v2/"
            };
            var request = new Hammock.RestRequest()
            {
                Path = "users/self/checkins"
            };
            request.AddParameter("oauth_token", token);
            var response = client.Request(request);
            return response.Content;
        }

        public static string AddTip(string token,string venueId,string text, string url = null)
        {
            var client = new Hammock.RestClient()
            {
                Authority = "https://api.foursquare.com/v2/"
            };
            var request = new Hammock.RestRequest()
            {
                Path = "users/tips/add"
            };
            request.AddField("oauth_token", token);
            request.AddField("venueId",venueId);
            request.AddField("text",text);
            if(!string.IsNullOrWhiteSpace(url)) request.AddField("url",url);
            var response = client.Request(request);
            return response.Content;
        }

        public static string MarkToDo(string token, string tipId)
        {
            var client = new Hammock.RestClient()
            {
                Authority = "https://api.foursquare.com/v2/"
            };
            var request = new Hammock.RestRequest()
            {
                Path = "tips/" + tipId
            };
            request.AddField("oauth_token", token);
            var response = client.Request(request);
            return response.Content;
        }
    }
}